/*
 * Corefarm experimental API - C++ 
 *
 * GPLv3 code
 *
 * (c) 2010 William Le Ferrand for Themipsfactory Ltd  ~ william@corefarm.com
 *
 */

#ifndef COREFARM_HPP_
#define COREFARM_HPP_

class corefarm_t {
  
  public: 
  connector_t(std::string &server, int port, std::string &job_id, std::string &key) ; 
  
  /* Log information on the corefarm */
  void log (std::string &msg); 
  void log (const char *msg);

  /***********************************************************/
  /* Those functions are usually used by the master process  */ 
  /***********************************************************/

  /* Start instances */
  void fire (int ghz) ; 

  /* Request remote execution of a function */
  int fork (std::string &entry, std::string &input); 
  int fork (const char *entry, std::string &input); 

  /* Get the result of a remote execution */
  std::string fetch (int slot); 

  /* Upload a file (in the global filesystem) */
  void global_upload (std::string &file);
  
  /* Save the result (before the master terminates) */
  void result (std::string &result); 

  /************************************************************/
  /* Those functions are usually used by the slave process    */
  /************************************************************/
  
  /* Download a file (from the job private filesystem) */
  std::string download (std::string &job_id, std::string &file); 
  
  /* Upload a file (on the job private filesystem) */
  void upload (std::string &job_id, std::string &file); 
  
  /* Pop a task from the task queue */
  struct task_t *pop () ; 
  
  /* Keepalives (slave only) */
  void keepalive (std::string &job_id, int slot) ; 
  void keepalive_idle () ; 
  
     
  
  

  private: 
    std::string perform (boost::asio::streambuf &request); 
    std::string escape (std::string &s); 

    std::string server; 
    int port; 
    std::string job_id;
   
};

#endif
